<?php
/*
    Author: Hong Ta
    CopyRight: ABC Company
*/


$this->beginContent('//layouts/main');
//$themeURL = Yii::app()->theme->getBaseUrl();

Yii::app()->clientScript->registerScript('logos',base64_decode(
    'JCh3aW5kb3cpLmxvYWQoZnVuY3Rpb24oKXt2YXIgYT0kKCIjcG93ZXJlZC1ieS14MmVuZ2luZSIpO2lmKCFhLmxlb'
    .'md0aHx8YS5hdHRyKCJzcmMiKSE9eWlpLmJhc2VVcmwrIi9pbWFnZXMvcG93ZXJlZF9ieV94MmVuZ2luZS5wbmciK'
    .'XskKCJhIikucmVtb3ZlQXR0cigiaHJlZiIpO2FsZXJ0KCJQbGVhc2UgcHV0IHRoZSBsb2dvIGJhY2siKX19KTs='));

$searchbarHtml = CHtml::beginForm(array('/search/search'), 'get',array('class' => 'form-search'))
        .'<span class="input-icon">
                                '.CHtml::textField('term',Yii::t('app', 'Search for contact, action, deal...'), array(
            'class' => 'input-small nav-search-input',
            'id'=>"nav-search-input",
            // 'autocomplete'=>"off",
            'onfocus' => 'toggleText(this);',
            'onblur' => 'toggleText(this);',
            'autocomplete' => 'off'
        )).'<i class="icon-search nav-search-icon"></i></span></form>';
$current_url = Yii::app()->controller->id;
$current_action = Yii::app()->controller->action->id;
?>
    <div class="breadcrumbs" id="breadcrumbs">
        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a style="text-decoration:none;" href="<?php echo $this->createUrl('site/whatsNew'); ?>">Home</a>

                <span class="divider">
                    <i class="icon-angle-right arrow-icon"></i>
                </span>
            </li>
        <?php if($current_url == 'site') : ?>
            <?php if($current_action == 'whatsNew') : ?>
                <li class="active">Activity</li>
            <?php else : ?>
                <li class="active"><?php echo ucfirst($current_action); ?></li>
            <?php endif; ?>
        <?php else : ?>
            <li class="active"><?php echo ucfirst($current_url); ?></li>
        <?php endif; ?>
        </ul><!--.breadcrumb-->
        <div class="nav-search" id="nav-search">
            <?php echo $searchbarHtml; ?>
        </div><!--#nav-search-->
    </div>
    <div class="page-content">
        <div class="page-header position-relative">
            <h1>
                <?php if($current_url == 'site') : ?>
                    <?php if($current_action == 'whatsNew') : ?>
                        Activity
                    <?php else : ?>
                        <?php echo ucfirst($current_action); ?>
                    <?php endif; ?>
                <?php else : ?>
                    <?php echo ucfirst($current_url); ?>
                <?php endif; ?>
                <!-- <small>
                    <i class="icon-double-angle-right"></i>
                    overview &amp; stats
                </small> -->
            </h1>
        </div><!--/.page-header -->
<!--<div id="sidebar-left">-->
    <!-- sidebar -->
    <?php

        $echoedFirstSideBarLeft = false;
        // Echoes sidebar left container div if it hasn't already been echoed. 
        function echoFirstSideBarLeft (&$echoedFirstSideBarLeft) {
            if (!$echoedFirstSideBarLeft) {
                echo '<div class="sidebar-left">';
                $echoedFirstSideBarLeft = true;
            }
        }

        if(isset($this->actionMenu) && !empty($this->actionMenu)) {
            echoFirstSideBarLeft ($echoedFirstSideBarLeft);
            $this->beginWidget('zii.widgets.CPortlet',array(
                'title'=>Yii::t('app','Actions'),
                'id'=>'actions'
            ));

            $this->widget(
                'zii.widgets.CMenu',array('items'=>$this->actionMenu,'encodeLabel'=>false));
            $this->endWidget();
        }

        foreach($this->leftPortlets as &$portlet) {
            echoFirstSideBarLeft ($echoedFirstSideBarLeft);
            $this->beginWidget('zii.widgets.CPortlet',$portlet['options']);
            echo $portlet['content'];
            $this->endWidget();
        }

        if(isset($this->modelClass) && 
           ($this->modelClass == 'Services' || $this->modelClass == 'Actions' ||
            $this->modelClass == 'BugReports' || $this->modelClass == 'X2Calendar' ||
            ($this->id=='site' && $this->action->id=='whatsNew'))) {
            echoFirstSideBarLeft ($echoedFirstSideBarLeft);
            $this->renderPartial ('_sidebarLeftExtraContent');
        }

        if ($echoedFirstSideBarLeft) echo "</div>";

        echo "<div class='sidebar-left'>";
        $this->widget('TopContacts',array(
            'id'=>'top-contacts',
            'widgetName' => 'TopContacts',
            'widgetLabel' => 'Top Contacts'
        ));
        echo "</div><div class='sidebar-left'>";
        $this->widget('RecentItems',array(
            'id'=>'recent-items',
            'widgetName' => 'RecentItems',
            'widgetLabel' => 'Recent Items'
        ));

        // collapse or expand left widget and save setting to user profile
        Yii::app()->clientScript->registerScript('leftWidgets','
            $(".left-widget-min-max").click(function(e){
                e.preventDefault();
                var link=this;
                var action = $(this).attr ("value");
                $.ajax({
                    url:"'.Yii::app()->request->getScriptUrl ().'/site/minMaxLeftWidget'.'",
                    data:{
                        action: action,
                        widgetName: $(link).attr ("name")
                    },
                    success:function(data){
                        if (data === "failure") return;
                        if(action === "expand"){
                            $(link).html("<img src=\'"+yii.themeBaseUrl+"/images/icons/'.
                                'Collapse_Widget.png\' />");
                            $(link).parents(".portlet-decoration").next().slideDown();
                            $(link).attr ("value", "collapse");
                        }else if(action === "collapse"){
                            $(link).html("<img src=\'"+yii.themeBaseUrl+"/images/icons/'.
                                'Expand_Widget.png\' />");
                            $(link).parents(".portlet-decoration").next().slideUp();
                            $(link).attr ("value", "expand");
                        }
                    }
                });
            });
        ');
        ?>
        </div>
<!--</div>-->
<!--</div>-->
    <div id="flexible-content">
        <div id="sidebar-right">
            <?php
            $this->widget('SortableWidgets', array(
                //list of items
                'portlets'=>$this->portlets,
                'jQueryOptions'=>array(
                    'opacity'=>0.6,    //set the dragged object's opacity to 0.6
                    'handle'=>'.portlet-decoration',    //specify tag to be used as handle
                    'distance'=>20,
                    'delay'=>150,
                    'revert'=>50,
                    'update'=>"js:function(){
                        $.ajax({
                                type: 'POST',
                                url: '{$this->createUrl('/site/widgetOrder')}',
                                data: $(this).sortable('serialize')
                        });
                    }"
                )
            ));
            ?>
        </div>
        <div id="content-container">
            <div id="content">
                <!-- content -->
                <?php echo $content; ?>
            </div>
        </div>
    </div>
</div>
<?php $this->endContent();
